package singleton;

/**
 * @author Brook
 *
 * 懒汉式双重检查，延迟加载效率高
 * 优点：线程安全；延迟加载，效率高
 * 为什么要double-check
 * 1.线程安全
 * 2.单check不行
 * 3.性能问题
 * 为什么要用volatile
 * 1.新建对象实际上有3个步骤
 */
public class Singleton6
{

    private volatile static Singleton6 instance;

    private Singleton6() {

    }

    public static Singleton6 getInstance() {
        if (instance == null) {
            synchronized(Singleton6.getInstance()){
                if(instance == null) {
                    instance = new Singleton6();
                }
            }

        }
        return instance;
    }
}
